package com.dsj.app.task;

import com.dsj.app.service.DrugOutService;
import com.dsj.app.service.ExpireNotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务
 * <p>
 * 1. 药品过期检查
 * 2. 药品库存检查
 */
@Component
public class InventoryCheckTask {

  private static final Logger log = LoggerFactory.getLogger(InventoryCheckTask.class);

  @Autowired
  private ExpireNotifyService expireNotifyService;

  @Autowired
  private DrugOutService drugOutService;

  /**
   * 检查药品过期
   * 每天 00:00 执行
   */
  @Scheduled(cron = "0 0 0  * * ?")
  public void checkExpire() {
    expireNotifyService.notifyDrugsExpiredToday();
    log.info("定时任务：发送药品过期提醒");
  }

  /**
   * 检查药品库存
   * 每天 00:00 执行
   */
  @Scheduled(cron = "0 0 0  * * ?")
  public void checkLowerLimit() {
    drugOutService.checkLowerLimit();
    log.info("定时任务：发送药品库存提醒");
  }
}
